package com.lbc.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lbc.bean.pojo.Page;
import com.lbc.bean.vo.KidAssistVO;
import com.lbc.common.resp.ResponseResult;
import com.lbc.service.KidAssistService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author xyl
 * @date 2021-03-29 17:59
 */
@Api(tags = "帮扶接口")
@RestController
@RequestMapping("assist")
public class AssistController {

    @Autowired
    private KidAssistService kidAssistService;

    @RequiresRoles("organization")
    @ApiOperation("帮扶")
    @GetMapping("/assist/{assistTo}")
    public ResponseResult assist(@PathVariable("assistTo") Integer assistTo ) {
        return ResponseResult.toResponse(kidAssistService.assist(assistTo));
    }

    @RequiresRoles(value = {"organization","admin"},logical = Logical.OR)
    @ApiOperation("机构的帮扶列表")
    @GetMapping("/list")
    public ResponseResult<PageInfo<KidAssistVO>> list(@Validated Page page,
                                                      @RequestParam(required = false) Integer orgId) {
        PageHelper.startPage(page.getPageNum(),page.getPageSize());
        return new ResponseResult<>(new PageInfo<>(kidAssistService.list(orgId)));
    }
}

